/**
 * This class contains generated code from the LWUIT resource editor, DO NOT MODIFY!
 * This class is designed for subclassing that way the code generator can overwrite it
 * anytime without erasing your changes which should exist in a subclass!
 * For details about this file and how it works please read this blog post:
 * http://lwuit.blogspot.com/2010/10/ui-builder-class-how-to-actually-use.html
*/
package generated;

import com.sun.lwuit.*;
import com.sun.lwuit.util.*;
import com.sun.lwuit.plaf.*;
import com.sun.lwuit.events.*;

public abstract class StateMachineBase extends UIBuilder {
    /**
     * this method should be used to initialize variables instead of
     * the constructor/class scope to avoid race conditions
     */
    protected void initVars() {}

    public StateMachineBase(Resources res, String resPath, boolean loadTheme) {
        startApp(res, resPath, loadTheme);
    }

    public Container startApp(Resources res, String resPath, boolean loadTheme) {
        initVars();
        if(loadTheme) {
            if(res == null) {
                try {
                    res = Resources.open(resPath);
                } catch(java.io.IOException err) { err.printStackTrace(); }
            }
            initTheme(res);
        }
        if(res != null) {
            setResourceFilePath(resPath);
            setResourceFile(res);
            return showForm("Main", null);
        } else {
            Form f = (Form)createContainer(resPath, "Main");
            beforeShow(f);
            f.show();
            postShow(f);
            return f;
        }
    }

    public Container createWidget(Resources res, String resPath, boolean loadTheme) {
        initVars();
        if(loadTheme) {
            if(res == null) {
                try {
                    res = Resources.open(resPath);
                } catch(java.io.IOException err) { err.printStackTrace(); }
            }
            initTheme(res);
        }
        return createContainer(resPath, "Main");
    }

    protected void initTheme(Resources res) {
            String[] themes = res.getThemeResourceNames();
            if(themes != null && themes.length > 0) {
                UIManager.getInstance().setThemeProps(res.getTheme(themes[0]));
            }
    }

    public StateMachineBase() {
    }

    public StateMachineBase(String resPath) {
        this(null, resPath, true);
    }

    public StateMachineBase(Resources res) {
        this(res, null, true);
    }

    public StateMachineBase(String resPath, boolean loadTheme) {
        this(null, resPath, loadTheme);
    }

    public StateMachineBase(Resources res, boolean loadTheme) {
        this(res, null, loadTheme);
    }

    public com.sun.lwuit.Container findContainer3(Container root) {
        return (com.sun.lwuit.Container)findByName("Container3", root);
    }

    public com.sun.lwuit.Container findContainer2(Container root) {
        return (com.sun.lwuit.Container)findByName("Container2", root);
    }

    public com.sun.lwuit.Container findContainer1(Container root) {
        return (com.sun.lwuit.Container)findByName("Container1", root);
    }

    public com.sun.lwuit.Button findButton4(Container root) {
        return (com.sun.lwuit.Button)findByName("Button4", root);
    }

    public com.sun.lwuit.Button findButton3(Container root) {
        return (com.sun.lwuit.Button)findByName("Button3", root);
    }

    public com.sun.lwuit.Button findButton2(Container root) {
        return (com.sun.lwuit.Button)findByName("Button2", root);
    }

    public com.sun.lwuit.TextArea findTextArea(Container root) {
        return (com.sun.lwuit.TextArea)findByName("TextArea", root);
    }

    public com.sun.lwuit.Form findShare(Container root) {
        return (com.sun.lwuit.Form)findByName("Share", root);
    }

    public com.sun.lwuit.Form findFriends(Container root) {
        return (com.sun.lwuit.Form)findByName("Friends", root);
    }

    public com.sun.lwuit.Dialog findWaitDialog(Container root) {
        return (com.sun.lwuit.Dialog)findByName("WaitDialog", root);
    }

    public com.sun.lwuit.Button findButton(Container root) {
        return (com.sun.lwuit.Button)findByName("Button", root);
    }

    public com.sun.lwuit.Form findMain(Container root) {
        return (com.sun.lwuit.Form)findByName("Main", root);
    }

    public com.sun.lwuit.Label findBirthday(Container root) {
        return (com.sun.lwuit.Label)findByName("Birthday", root);
    }

    public com.sun.lwuit.Label findLabel1(Container root) {
        return (com.sun.lwuit.Label)findByName("Label1", root);
    }

    public com.sun.lwuit.Label findProfileName(Container root) {
        return (com.sun.lwuit.Label)findByName("ProfileName", root);
    }

    public com.sun.lwuit.Label findName(Container root) {
        return (com.sun.lwuit.Label)findByName("name", root);
    }

    public com.sun.lwuit.Label findProfilePic(Container root) {
        return (com.sun.lwuit.Label)findByName("ProfilePic", root);
    }

    public com.sun.lwuit.Label findLastname(Container root) {
        return (com.sun.lwuit.Label)findByName("Lastname", root);
    }

    public com.sun.lwuit.List findList(Container root) {
        return (com.sun.lwuit.List)findByName("List", root);
    }

    public com.sun.lwuit.Container findContainer(Container root) {
        return (com.sun.lwuit.Container)findByName("Container", root);
    }

    public com.sun.lwuit.CheckBox findCache(Container root) {
        return (com.sun.lwuit.CheckBox)findByName("cache", root);
    }

    public com.sun.lwuit.Container findContact(Container root) {
        return (com.sun.lwuit.Container)findByName("Contact", root);
    }

    public com.sun.lwuit.Form findProfile(Container root) {
        return (com.sun.lwuit.Form)findByName("Profile", root);
    }

    public com.sun.lwuit.Label findPic(Container root) {
        return (com.sun.lwuit.Label)findByName("pic", root);
    }

    public com.sun.lwuit.TextArea findMessage(Container root) {
        return (com.sun.lwuit.TextArea)findByName("message", root);
    }

    public com.sun.lwuit.List findAlbums(Container root) {
        return (com.sun.lwuit.List)findByName("albums", root);
    }

    public com.sun.lwuit.Label findLabel(Container root) {
        return (com.sun.lwuit.Label)findByName("Label", root);
    }

    public com.sun.lwuit.Button findButton1(Container root) {
        return (com.sun.lwuit.Button)findByName("Button1", root);
    }

    public static final int COMMAND_MainFriends = 40;
    public static final int COMMAND_MainShare = 39;
    public static final int COMMAND_MainExit = 41;
    public static final int COMMAND_MainAlbums = 42;
    public static final int COMMAND_MainCurrentUser = 36;

    protected boolean onMainFriends() {
        return false;
    }

    protected boolean onMainShare() {
        return false;
    }

    protected boolean onMainExit() {
        return false;
    }

    protected boolean onMainAlbums() {
        return false;
    }

    protected boolean onMainCurrentUser() {
        return false;
    }

    protected void processCommand(ActionEvent ev, Command cmd) {
        switch(cmd.getId()) {
            case COMMAND_MainFriends:
                if(onMainFriends()) {
                    ev.consume();
                }
                return;

            case COMMAND_MainShare:
                if(onMainShare()) {
                    ev.consume();
                }
                return;

            case COMMAND_MainExit:
                if(onMainExit()) {
                    ev.consume();
                }
                return;

            case COMMAND_MainAlbums:
                if(onMainAlbums()) {
                    ev.consume();
                }
                return;

            case COMMAND_MainCurrentUser:
                if(onMainCurrentUser()) {
                    ev.consume();
                }
                return;

        }
    }

    protected void exitForm(Form f) {
        if("WaitDialog".equals(f.getName())) {
            exitWaitDialog(f);
            return;
        }

        if("Main".equals(f.getName())) {
            exitMain(f);
            return;
        }

        if("Albums".equals(f.getName())) {
            exitAlbums(f);
            return;
        }

        if("Friends".equals(f.getName())) {
            exitFriends(f);
            return;
        }

        if("Contact".equals(f.getName())) {
            exitContact(f);
            return;
        }

        if("Profile".equals(f.getName())) {
            exitProfile(f);
            return;
        }

        if("Share".equals(f.getName())) {
            exitShare(f);
            return;
        }

    }


    protected void exitWaitDialog(Form f) {
    }


    protected void exitMain(Form f) {
    }


    protected void exitAlbums(Form f) {
    }


    protected void exitFriends(Form f) {
    }


    protected void exitContact(Form f) {
    }


    protected void exitProfile(Form f) {
    }


    protected void exitShare(Form f) {
    }

    protected void beforeShow(Form f) {
        if("WaitDialog".equals(f.getName())) {
            beforeWaitDialog(f);
            return;
        }

        if("Main".equals(f.getName())) {
            beforeMain(f);
            return;
        }

        if("Albums".equals(f.getName())) {
            beforeAlbums(f);
            return;
        }

        if("Friends".equals(f.getName())) {
            beforeFriends(f);
            return;
        }

        if("Contact".equals(f.getName())) {
            beforeContact(f);
            return;
        }

        if("Profile".equals(f.getName())) {
            beforeProfile(f);
            return;
        }

        if("Share".equals(f.getName())) {
            beforeShare(f);
            return;
        }

    }


    protected void beforeWaitDialog(Form f) {
    }


    protected void beforeMain(Form f) {
    }


    protected void beforeAlbums(Form f) {
    }


    protected void beforeFriends(Form f) {
    }


    protected void beforeContact(Form f) {
    }


    protected void beforeProfile(Form f) {
    }


    protected void beforeShare(Form f) {
    }

    protected void beforeShowContainer(Container c) {
        if("WaitDialog".equals(c.getName())) {
            beforeContainerWaitDialog(c);
            return;
        }

        if("Main".equals(c.getName())) {
            beforeContainerMain(c);
            return;
        }

        if("Albums".equals(c.getName())) {
            beforeContainerAlbums(c);
            return;
        }

        if("Friends".equals(c.getName())) {
            beforeContainerFriends(c);
            return;
        }

        if("Contact".equals(c.getName())) {
            beforeContainerContact(c);
            return;
        }

        if("Profile".equals(c.getName())) {
            beforeContainerProfile(c);
            return;
        }

        if("Share".equals(c.getName())) {
            beforeContainerShare(c);
            return;
        }

    }


    protected void beforeContainerWaitDialog(Container c) {
    }


    protected void beforeContainerMain(Container c) {
    }


    protected void beforeContainerAlbums(Container c) {
    }


    protected void beforeContainerFriends(Container c) {
    }


    protected void beforeContainerContact(Container c) {
    }


    protected void beforeContainerProfile(Container c) {
    }


    protected void beforeContainerShare(Container c) {
    }

    protected void postShow(Form f) {
        if("WaitDialog".equals(f.getName())) {
            postWaitDialog(f);
            return;
        }

        if("Main".equals(f.getName())) {
            postMain(f);
            return;
        }

        if("Albums".equals(f.getName())) {
            postAlbums(f);
            return;
        }

        if("Friends".equals(f.getName())) {
            postFriends(f);
            return;
        }

        if("Contact".equals(f.getName())) {
            postContact(f);
            return;
        }

        if("Profile".equals(f.getName())) {
            postProfile(f);
            return;
        }

        if("Share".equals(f.getName())) {
            postShare(f);
            return;
        }

    }


    protected void postWaitDialog(Form f) {
    }


    protected void postMain(Form f) {
    }


    protected void postAlbums(Form f) {
    }


    protected void postFriends(Form f) {
    }


    protected void postContact(Form f) {
    }


    protected void postProfile(Form f) {
    }


    protected void postShare(Form f) {
    }

    protected void postShowContainer(Container c) {
        if("WaitDialog".equals(c.getName())) {
            postContainerWaitDialog(c);
            return;
        }

        if("Main".equals(c.getName())) {
            postContainerMain(c);
            return;
        }

        if("Albums".equals(c.getName())) {
            postContainerAlbums(c);
            return;
        }

        if("Friends".equals(c.getName())) {
            postContainerFriends(c);
            return;
        }

        if("Contact".equals(c.getName())) {
            postContainerContact(c);
            return;
        }

        if("Profile".equals(c.getName())) {
            postContainerProfile(c);
            return;
        }

        if("Share".equals(c.getName())) {
            postContainerShare(c);
            return;
        }

    }


    protected void postContainerWaitDialog(Container c) {
    }


    protected void postContainerMain(Container c) {
    }


    protected void postContainerAlbums(Container c) {
    }


    protected void postContainerFriends(Container c) {
    }


    protected void postContainerContact(Container c) {
    }


    protected void postContainerProfile(Container c) {
    }


    protected void postContainerShare(Container c) {
    }

    protected void onCreateRoot(String rootName) {
        if("WaitDialog".equals(rootName)) {
            onCreateWaitDialog();
            return;
        }

        if("Main".equals(rootName)) {
            onCreateMain();
            return;
        }

        if("Albums".equals(rootName)) {
            onCreateAlbums();
            return;
        }

        if("Friends".equals(rootName)) {
            onCreateFriends();
            return;
        }

        if("Contact".equals(rootName)) {
            onCreateContact();
            return;
        }

        if("Profile".equals(rootName)) {
            onCreateProfile();
            return;
        }

        if("Share".equals(rootName)) {
            onCreateShare();
            return;
        }

    }


    protected void onCreateWaitDialog() {
    }


    protected void onCreateMain() {
    }


    protected void onCreateAlbums() {
    }


    protected void onCreateFriends() {
    }


    protected void onCreateContact() {
    }


    protected void onCreateProfile() {
    }


    protected void onCreateShare() {
    }

    protected boolean setListModel(List cmp) {
        String listName = cmp.getName();
        if("List".equals(listName)) {
            return initListModelList(cmp);
        }
        if("albums".equals(listName)) {
            return initListModelAlbums(cmp);
        }
        return super.setListModel(cmp);
    }

    protected boolean initListModelList(List cmp) {
        return false;
    }

    protected boolean initListModelAlbums(List cmp) {
        return false;
    }

    protected void handleComponentAction(Component c, ActionEvent event) {
        Container rootContainerAncestor = getRootAncestor(c);
        if(rootContainerAncestor == null) return;
        String rootContainerName = rootContainerAncestor.getName();
        if(rootContainerName == null) return;
        if(rootContainerName.equals("Main")) {
            if("Button2".equals(c.getName())) {
                onMain_Button2Action(c, event);
                return;
            }
            if("Button3".equals(c.getName())) {
                onMain_Button3Action(c, event);
                return;
            }
            if("Button1".equals(c.getName())) {
                onMain_Button1Action(c, event);
                return;
            }
            if("Button4".equals(c.getName())) {
                onMain_Button4Action(c, event);
                return;
            }
            if("cache".equals(c.getName())) {
                onMain_CacheAction(c, event);
                return;
            }
        }
        if(rootContainerName.equals("Albums")) {
            if("albums".equals(c.getName())) {
                onAlbums_AlbumsAction(c, event);
                return;
            }
        }
        if(rootContainerName.equals("Friends")) {
            if("List".equals(c.getName())) {
                onFriends_ListAction(c, event);
                return;
            }
        }
        if(rootContainerName.equals("Share")) {
            if("TextArea".equals(c.getName())) {
                onShare_TextAreaAction(c, event);
                return;
            }
            if("message".equals(c.getName())) {
                onShare_MessageAction(c, event);
                return;
            }
            if("Button1".equals(c.getName())) {
                onShare_Button1Action(c, event);
                return;
            }
            if("Button".equals(c.getName())) {
                onShare_ButtonAction(c, event);
                return;
            }
        }
    }

      protected void onMain_Button2Action(Component c, ActionEvent event) {
      }

      protected void onMain_Button3Action(Component c, ActionEvent event) {
      }

      protected void onMain_Button1Action(Component c, ActionEvent event) {
      }

      protected void onMain_Button4Action(Component c, ActionEvent event) {
      }

      protected void onMain_CacheAction(Component c, ActionEvent event) {
      }

      protected void onAlbums_AlbumsAction(Component c, ActionEvent event) {
      }

      protected void onFriends_ListAction(Component c, ActionEvent event) {
      }

      protected void onShare_TextAreaAction(Component c, ActionEvent event) {
      }

      protected void onShare_MessageAction(Component c, ActionEvent event) {
      }

      protected void onShare_Button1Action(Component c, ActionEvent event) {
      }

      protected void onShare_ButtonAction(Component c, ActionEvent event) {
      }

}
